|
|
|
|
|
|
|
Figure 12.19
Rotating an object around its center. |
|
|
|
 |
|
|
|
|
Result(1, 1) = sx
Result(2, 2) = sy
End Sub
' Create a rotation matrix for rotating by the
' given angle (in radians). Public Sub m2Rotate(Result() As Single, ByVal theta As Single)
m2Identity Result
Result(1, 1) = Cos(theta)
Result(1, 2) = Sin(theta)
Result(2, 1) = -Result(1, 2)
Result(2, 2) = Result(1, 1)
End Sub |
|
|
|
|
|
|
|
|
Sometimes you will find it easier to specify a rotation with a point that should be rotated until it lies along the X or Y axis rather than specifying an angle of rotation. When you want to reflect across an arbitrary line, for instance, you need to rotate the line until it lies in the X axis. Specifying a point on the line is easier than calculating the angle through which the line must be rotated. |
|
|
|
|
|
|
|
|
Figure 12.20 shows a point that should be rotated into the X axis. The distance d is the distance from the point to the origin and equals Sqr(x * x + y * y). Because q is measured in the negative direction, Cos(q) = x / d and Sin(q) = y / d. In that case, the rotation transformation matrix becomes: |
|
|
|
|
|